package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("新增图书");
        int currentSize=bookList.getUsedSize();
        if(currentSize==10){
            System.out.println("书架已满..");
            return;
        }
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入书名");
        String name=scanner.nextLine();
        for (int i = 0; i <currentSize; i++) {
            Book book=bookList.getBook(i);
            if(name.equals(book.getName())){
                System.out.println("书架上已有这本书..");
                System.out.println(book);
                return;
            }
        }
        System.out.println("请输入作者");
        String author=scanner.nextLine();
        System.out.println("请输入类型");
        String kind=scanner.nextLine();
        System.out.println("请输入价格");
        int price=scanner.nextInt();
        Book book=new Book(name,author,price,kind);
        bookList.setBook(bookList.getUsedSize(), book);
        bookList.setUsedSize(bookList.getUsedSize()+1);
        System.out.println("添加成功");
    }
}
